package com.sy.core.util;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

import java.io.Serializable;

/**
 * 
 * All rights Reserved, Designed By Chong.CaiXin
 * 
 * @Title: RestResult.java
 * @Package com.shadow.core.entity
 * @Description: (统一 的接口返回类)
 * @author: Chong.CaiXin
 * @date: 2018年6月26日 下午4:20:35
 * @version V1.0
 * @Copyright: 2018 Chong.CaiXin. All rights reserved.
 *
 */
public class  RestResult implements Serializable {
	/**
	 * 返回请求结果 true 成功 false 失败
	 */
	private boolean success;
	/**
	 * 返回处理消息
	 */
	private String message;
	/**
	 * 返回处理数据
	 */
	private Object data;
	/**
	 * 操作码 200成功 404页面丢失 500异常错误 691 参数异常 201登录过期 405 账户异常 406 验证码错误
	 */
	private String code;


	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public RestResult() {
	}

	public RestResult(boolean success, String message, Object data) {
		this.success = success;
		this.message = message;
		this.data = data;
	}

	public RestResult(String code,String message, Object data) {
		this.message = message;
		this.data = data;
		this.code = code;
	}

	public RestResult(boolean success, String message) {
		this.success = success;
		this.message = message;
	}

	public RestResult(String code,String message) {
		this.message = message;
		this.code = code;
	}

	public String  getResultStr(RestResult result){
		return result != null ? JSON.toJSONString(result, SerializerFeature.WriteMapNullValue) : "";
	}
}